<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form divClass" v-if="headerShow">
        <a-form size="small" :model="pageData.queryData" layout="inline">
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="流转卡号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.flowCardCode"
                allow-clear
              />
            </a-form-item>
          </a-col>
        </a-form>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <Toolbar
          :items="['查询', '新增', '删除', '审核']"
          @add="addHandler"
          @del="deleteHandler"
          @select="selectHandler"
          @audit="setAudit"
        >
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        @selection-changed="onSelectionChanged"
        rowSelection="multiple"
        @grid-ready="gridReady"
        style="height: 100%"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="table.dataList"
        :columnDefs="pageData.tc"
        :localeText="localeText1"
        :suppressRowClickSelection="true"
      ></AgGridVuesCopys>
    </template>

    <paginationCopys
      :page-size="pagination.pageSize"
      :current="pagination.page"
      :total="pagination.total"
      show-total
      show-jumper
      show-page-size
      @change="nextDoRefreshPage"
      @page-size-change="nextDoRefreshSize"
      style="justify-content: center"
    />

    <a-drawer
      placement="bottom"
      :drawer-style="{ zIndex: 9999 }"
      :mask-closable="false"
      height="60%"
      :visible="pageData.showAdd"
      unmountOnClose
      @ok="sideOk"
      :ok-loading="saveLoading"
      @cancel="pageData.showAdd = false"
      cancel-text="关闭"
      ok-text="保存"
    >
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div style="height: 100%">
        <a-form ref="formRef" :model="dataForm" layout="horizontal">
          <a-row class="grid-demo" :gutter="24">
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="流转卡号"
                field="flowCardCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input-search
                  class="bacClass"
                  placeholder="请输入流转卡扫描"
                  v-model="dataForm.flowCardCode"
                  button-text="提取"
                  search-button
                  @search="search"
                />
              </a-form-item>
            </a-col>
            <!-- <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="记录单号"
                field="recordCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.recordCode" />
              </a-form-item>
            </a-col> -->
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="坯布编号"
                field="greyCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.greyCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="坯布名称"
                field="greyName"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.greyName" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="布票号"
                field="clothVoteCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.clothVoteCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="色号"
                field="colorCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.colorCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="色称"
                field="colorName"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.colorName" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="匹数"
                field="houseNum"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.houseNum" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="总分数"
                field="totalBranchNum"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.totalBranchNum" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                label-col-flex="50px"
                label="评定"
                field="qualifiedNum"
                :validate-trigger="['change', 'blur']"
              >
                <div class="flex"
                  ><span
                    style="
                      background-color: red;
                      color: #fff;
                      border: 1px solid black;
                      width: 85px;
                      height: 30px;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                    "
                    >不合格</span
                  ><span class="flex items-center">≥</span
                  ><span
                    ><a-input-number
                      style="width: 80px"
                      v-model="dataForm.qualifiedNum"
                      class="bacClass"
                      :min="0"
                      :precision="0" /></span
                  ><span class="flex items-center">＜</span
                  ><span
                    style="
                      background-color: green;
                      color: #fff;
                      border: 1px solid black;
                      width: 50px;
                      height: 30px;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                    "
                    >合格</span
                  ></div
                >
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="评定结果"
                field="result"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" disabled v-model="dataForm.result" />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
        <div style="width: 100%; height: 62%" class="mt-4">
          <encapsulation-agrid
            ref="drawerTableRef"
            :configaggrid="configaggrid"
          ></encapsulation-agrid>
        </div>
        <div class="tips"> </div>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
  import { post, get } from '@/api/http'
  import { useTable, usePagination, useTableColumn } from '@/hooks/table'
  import { ref, reactive, onMounted } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import { FormInstance } from '@arco-design/web-vue/es/form'
  import 'ag-grid-community/styles/ag-grid.css'
  import 'ag-grid-community/styles/ag-theme-alpine.css'
  import { localeText } from '@/api/aggridZw'
  
  interface paramData {
    id: any
    verifyclothDate: string | undefined
    foodHair: string | undefined
    burnHair: string | undefined
    planOrderCode: string | undefined
    goodsNum: string | undefined
    deadCottom: string | undefined
    hairHair: string | undefined
    goodsNo: string | number
    verifyclothResult: any | undefined
    resultComment: string | undefined
    remark: string | undefined
    verifyclothDetail: any[]
    totalBranchNum: number
    flowCardCode: any
    recordCode: any | undefined
    customName: any | undefined
    customOrderCode: any | undefined
    productName: any | undefined
  }
  export default {
    //试纱验布登记
    name: 'TestYarnRegistration',
    setup() {
      //隐藏显示头部
      const headerShow = ref<boolean>(true)
      const saveLoading = ref<boolean>(false)
      const pageData = reactive<{
        showAdd: boolean
        sideTitle: string
        dropDownData: any
        pageLoading: boolean
        theight: number
        rHeight: number | undefined
        labelColFlex: string
        labelColFlex1: string
        queryData: any
        tc: any
        fromData: any
        totalBranchNum: any
      }>({
        showAdd: false,
        sideTitle: '新增中检验布表',
        dropDownData: '',
        pageLoading: false,
        theight: 0,
        rHeight: 0,
        labelColFlex: '120px',
        labelColFlex1: '80px',
        queryData: {
          flowCardCode: '',
          deleteState: 0,
        },
        tc: [],
        fromData: [],
        totalBranchNum: '',
      })
      const drawerTableData = ref<any>([])
      const drawerTableRef = ref<any>(null)
      //查询列表
      onMounted(() => {
        // tableHeader()
        selectHandler()
      })

      //切换分页
      const nextDoRefreshPage = (val: any) => {
        pagination.page = val
        doRefresh()
      }
      const nextDoRefreshSize = (val: any) => {
        pagination.pageSize = val
        doRefresh()
      }
      const pagination = usePagination(doRefresh)
      const table = useTable()
      function doRefresh() {
        pageData.pageLoading = true
        pageData.queryData.page = pagination.page
        pageData.queryData.size = pagination.pageSize
        //默认表头
        let tbList: any = [
          {
            title: '流转卡号',
            key: 'flowCardCode',
            dataIndex: 'flowCardCode',
          },
          {
            title: '记录单号',
            key: 'recordCode',
            dataIndex: 'recordCode',
          },
          {
            title: '坯布编号',
            key: 'greyCode',
            dataIndex: 'greyCode',
          },
          {
            title: '坯布名称',
            key: 'greyName',
            dataIndex: 'greyName',
          },
          {
            title: '布票号',
            key: 'clothVoteCode',
            dataIndex: 'clothVoteCode',
          },
          {
            title: '色号',
            key: 'colorCode',
            dataIndex: 'colorCode',
          },
          {
            title: '色称',
            key: 'colorName',
            dataIndex: 'colorName',
          },
          {
            title: '匹数',
            key: 'houseNum',
            dataIndex: 'houseNum',
          },
        ]
        post({
          url: 'dwQms/verifyYarnRegister/getPage',
          data: pageData.queryData,
        })
          .then(({ data, code }: any) => {
            if (code === 200) {
              //拼接渲染动态表头
              //重新构造动态表头的数组对象
              const asyncColumns = data.defectName.map((item: any) => {
                return {
                  title: item,
                  key: item,
                  dataIndex: item,
                }
              })
              tbList = tbList.concat(asyncColumns)
              const otherDefaultColumns = [
                {
                  title: '合格标准分数',
                  key: 'qualifiedNum',
                  dataIndex: 'qualifiedNum',
                },
                {
                  title: '总分数',
                  key: 'totalBranchNum',
                  dataIndex: 'totalBranchNum',
                },
                {
                  title: '试纱结果状态',
                  key: 'resultState',
                  dataIndex: 'resultState',
                  cellRenderer: (params: any) => {
                    if (params.value == '0') {
                      return '不合格'
                    } else if (params.value == '1') {
                      return '合格'
                    } else {
                      return ''
                    }
                  },
                },
                {
                  title: '审核状态',
                  key: 'auditState',
                  dataIndex: 'auditState',
                  cellRenderer: (params: any) => {
                    if (params.value == '0') {
                      return '未审核'
                    } else if (params.value == '1') {
                      return '通过'
                    } else if (params.value == '2') {
                      return '不通过'
                    }
                  },
                },
                {
                  title: '审核人',
                  key: 'auditName',
                  dataIndex: 'auditName',
                },
                {
                  title: '审核时间',
                  key: 'auditTime',
                  dataIndex: 'auditTime',
                },
                {
                  title: '备注',
                  key: 'remark',
                  dataIndex: 'remark',
                },
                {
                  title: '删除状态',
                  key: 'deleteState',
                  dataIndex: 'deleteState',
                  cellRenderer: (params: any) => {
                    if (params.value == '0') {
                      return '未删除'
                    } else if (params.value == '1') {
                      return '已删除'
                    } else {
                      return ''
                    }
                  },
                },
                {
                  title: '创建人',
                  key: 'createName',
                  dataIndex: 'createName',
                },
                {
                  title: '创建时间',
                  key: 'createTime',
                  dataIndex: 'createTime',
                },
                {
                  title: '修改人',
                  key: 'updateName',
                  dataIndex: 'updateName',
                },
                {
                  title: '修改时间',
                  key: 'updateTime',
                  dataIndex: 'updateTime',
                },
              ]
              tbList = tbList.concat(otherDefaultColumns)
              tb(tbList)
              // console.log(tbList)
              const list = data.list.map((item: any) => {
                for (let i = 0; i < item.detailList.length; i++) {
                  item[item.detailList[i].defectName] = item.detailList[i].defectNum
                }
                return item
              })
              // console.log('list', list)
              table.handleSuccess(list)
              pagination.setTotalSize(data.total)
              gridOption.value.setRowData(list)
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
      }
      //查询
      const selectHandler = () => {
        pagination.page = 1
        doRefresh()
      }
      //------新增、修改页面开始------
      const dataForm = reactive<any>({
        id: null,
        flowCardCode: '',
        verifyclothDate: '',
        foodHair: '',
        burnHair: '',
        planOrderCode: '',
        goodsNum: '',
        deadCottom: '',
        hairHair: '',
        goodsNo: '',
        verifyclothResult: 0,
        resultComment: '',
        remark: '',
        verifyclothDetail: [],
        result: '',
        detailList: [],
        recordCode: '',
        greyCode: '',
        greyName: '',
        clothVoteCode: '',
        colorCode: '',
        colorName: '',
        houseNum: '',
        qualifiedNum: null,
        totalBranchNum: null,
        resultState: null,
      })
      const drawerTableColumn = ref<any>([])
      let configaggrid = ref({
        url: '', //接口路径
        queryData: {
          //接口参数
        },
        paginationShow: false, //分页是否显示
        invokeiIterface: false, //是否调用接
        rowMultiSelectWithClick: false, //点击行是否多选
        column: drawerTableColumn,
      })
      const totalObj = reactive({})
      const countTotal = (obj: any) => {
        dataForm.totalBranchNum = 0
        for (let key in obj) {
          dataForm.totalBranchNum += obj[key]
        }
      }
      const addHandler = async () => {
        try {
          drawerTableData.value = []
          drawerTableColumn.value = []
          for (var key in dataForm) {
            if (key === 'id') {
              dataForm[key] = null
            } else if (key === 'verifyclothDetail') {
              dataForm[key] = []
            } else {
              dataForm[key] = ''
            }
          }
          pageData.showAdd = true
          pageData.sideTitle = '新增试纱验布表'
          const res = await get({
            url: 'dwQms/ExamineSetting/getListByVerifyYarn',
          })
          if (res.code == 200) {
            const { data } = res
            console.log(data)
            for (let key in data) {
              const obj = {}
              if (data[key][0].computeMode == 0) {
                //计算方式为疵点范围计算 编辑为输入框 根据输入的范围去计算分数
                obj['headerName'] = key
                obj['field'] = key
                obj['defectScore'] = data[key].map((item: any) => {
                  return {
                    minRange: item.minRange,
                    maxRange: item.maxRange,
                    defectScore: item.defectScore,
                  }
                })
                obj['editable'] = true
                obj['cellEditor'] = 'agNumberCellEditor'
                obj['valueParser'] = (params: any) => {
                  //判断输入的是不是正数
                  if (params.newValue < 0 || isNaN(params.newValue)) {
                    return 0
                  } else {
                    return Math.round(params.newValue)
                  }
                }
                obj['onCellValueChanged'] = (params: any) => {
                  const value = params.newValue
                  const filterDefectScore = data[key].find(
                    (item: any) => item.minRange <= value && item.maxRange >= value
                  )['defectScore']
                  totalObj[params.colDef.headerName] = params.newValue * filterDefectScore
                  countTotal(totalObj)
                }
              } else if (data[key][0].computeMode == 1) {
                //1的情况是可选值 双击编辑是下拉框 选择对应方案去计算分数
                obj['headerName'] = key
                obj['field'] = key
                obj['defectScore'] = data[key].map((item: any) => {
                  return {
                    [item.chooseableValue]: item.chooseScore,
                  }
                })
                obj['editable'] = true
                obj['cellEditor'] = 'agRichSelectCellEditor'
                //渲染下拉框的可选值
                obj['cellEditorParams'] = {
                  values: data[key].map((item: any) => {
                    return item.choosableValue
                  }),
                }
                obj['onCellValueChanged'] = (params: any) => {
                  const value = params.newValue
                  const filterDefectScore = data[key].find(
                    (item: any) => item.choosableValue == value
                  )['chooseScore']
                  totalObj[params.colDef.headerName] = parseInt(filterDefectScore)
                  countTotal(totalObj)
                }
              }
              drawerTableColumn.value.push(obj)
            }
            pageData.fromData = [
              drawerTableColumn.value.reduce((sum: any, item: any) => {
                sum[item.headerName] = null
                return sum
              }, {}),
            ]
            nextTick(() => {
              console.log(drawerTableRef.value)
              drawerTableRef.value.setdataListIterface(pageData.fromData)
            })
          } else {
            Message.error(res.message)
          }
        } catch (error) {
          console.log(error)
        }
      }
      const editHandler = (record: paramData) => {
        for (var key in record) {
          dataForm[key] = record[key]
        }
        for (var i = 0; i < pageData.fromData.length; i++) {
          pageData.fromData[i].defectNum = 0
          let defectNum: any = ''
          let id: any = null
          let verifyclothId: any = null
          for (let index1 = 0; index1 < dataForm.verifyclothDetail.length; index1++) {
            if (pageData.fromData[i].defectName == dataForm.verifyclothDetail[index1].defectName) {
              id = dataForm.verifyclothDetail[index1].id
              verifyclothId = dataForm.verifyclothDetail[index1].verifyclothId
              defectNum = Number(dataForm.verifyclothDetail[index1].defectNum)
              break
            }
          }
          pageData.fromData[i].defectNum = defectNum
          pageData.fromData[i].id = id
          pageData.fromData[i].verifyclothId = verifyclothId
        }
        pageData.sideTitle = '修改中检验布表'
        pageData.showAdd = true
      }
      const setAudit = () => {
        if (gridOption.value.getSelectedRows().length <= 0) {
          Message.error({
            content: '请勾选数据进行审核！',
            duration: 5000,
          })
          return
        }
        if (!gridOption.value.getSelectedRows().every((item: any) => item.auditState == 0)) {
          Message.error({
            content: '只能选择未审核的数据进行审核！',
            duration: 5000,
          })
          return
        }
        Modal.confirm({
          title: '系统提示',
          content: '确认审核选中的数据?',
          async onOk() {
            const idList = gridOption.value.getSelectedRows().map((item: any) => item.id)
            var obj: any = {
              ids: idList,
              auditState: 1,
            }
            try {
              const res = await post({
                url: 'dwQms/verifyYarnRegister/setAudit',
                data: obj,
              })
              if (res.code === 200) {
                Message.success({
                  content: '操作成功',
                  duration: 5000,
                })
                pagination.page = 1
                selectHandler()
              } else {
                Message.error({
                  content: '操作失败',
                  duration: 5000,
                })
              }
            } catch (error) {
              console.log(error)
            }
          },
        })
      }
      const formRef = ref<FormInstance>()
      watch(
        () => dataForm.totalBranchNum,
        (newVal) => {
          if (!dataForm.qualifiedNum) return
          if (newVal >= dataForm.qualifiedNum) {
            console.log(newVal)
            dataForm.result = '不合格'
          } else if (newVal && newVal > 0 && newVal < dataForm.qualifiedNum) {
            dataForm.result = '合格'
          } else {
            dataForm.result = ''
          }
        }
      )
      const sideOk = () => {
        saveLoading.value = true
        formRef.value?.validate().then(async (err) => {
          if (!err) {
            dataForm.verifyclothDetail = pageData.fromData
            if (pageData.sideTitle === '新增试纱验布表') {
              dataForm.resultState = dataForm.result == '合格' ? '1' : '0'
              dataForm.auditState = '0'
              dataForm.deleteState = '0'
              const defectObj = drawerTableRef.value.getListData()[0]
              console.log('defectObj', defectObj)

              const detailList = []
              for (let key in defectObj) {
                const obj = {
                  defectCode: key,
                  defectName: key,
                  defectNum: defectObj[key],
                }
                detailList.push(obj)
              }
              dataForm.detailList = detailList
              console.log(dataForm)
              try {
                const res = await post({
                  url: 'dwQms/verifyYarnRegister/insert',
                  data: dataForm,
                })
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  pageData.showAdd = false
                  Message.success({
                    content: '新增成功',
                    duration: 5000,
                  })
                  doRefresh()
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              } catch (error) {
                console.log(error)
              } finally {
                saveLoading.value = false
              }
            }
          } else {
            saveLoading.value = false
          }
        })
      }
      //------新增、修改页面结束------
      //------删除方法开始------
      const deleteHandler = () => {
        if (gridOption.value.getSelectedRows().length === 0) {
          return
        }
        Modal.confirm({
          title: '系统提示',
          content: '确认删除选中的数据?',
          onOk() {
            post({
              url: 'dwQms/verifyYarnRegister/delete',
              data: gridOption.value.getSelectedRows().map((o: any) => {
                return o.id
              }),
            }).then(({ code, data, message }: any) => {
              if (code === 200) {
                Message.success({
                  content: '删除成功',
                  duration: 5000,
                })

                pagination.page = 1
                doRefresh()
              } else {
                Message.error({
                  content: message,
                  duration: 5000,
                })
              }
            })
          },
        })
      }
      //------删除方法结束------

      // 表格准备事件
      const gridOption = ref()
      const gridReady = (params: any) => {
        gridOption.value = params.api
      }
      const gridOption2 = ref()
      const gridReady2 = (params: any) => {
        gridOption2.value = params.api
      }
      const defaultColDef = {
        sortable: true,
        resizable: true,
        filter: true,
        // flex: 1
      }
      const localeText1: any = ref(localeText)
      function tb(tbList: any[]) {
        pageData.tc = tbList.map((o) => {
          let obj = {
            headerName: o.title,
            field: o.key,
            pinned: o['fixed'],
            width: o.width,
            cellRenderer: o.cellRenderer,
          }

          if (o.slotName === 'act') {
            obj['resizable'] = false
            obj['filter'] = false
            obj['sortable'] = false
            obj['lockPosition'] = o.fixed
            obj['cellRenderer'] = {
              template: `<el-button style="color:#165dff;" link @click="a()">修改</el-button>`,
              setup(props: any) {
                const a = () => {
                  editHandler(props.params.data)
                }
                return {
                  a,
                }
              },
            }
          }
          return obj
        })
        let a = [
          {
            showRowGroup: 'hide_def',
            headerName: '',
            checkboxSelection: true,
            headerCheckboxSelection: true,
            pinned: 'left',
            width: 50,
            resizable: false,
            filter: false,
            sortable: false,
            minWidth: 50,
            maxWidth: 50,
            lockPosition: 'left',
          },
        ]
        pageData.tc = a.concat(pageData.tc)
      }
      const tableHeader = () => {
        let tbList: any = [
          {
            title: '流转卡号',
            key: 'flowCardCode',
            dataIndex: 'flowCardCode',
          },
          {
            title: '记录单号',
            key: 'recordCode',
            dataIndex: 'recordCode',
          },
          {
            title: '坯布编号',
            key: 'greyCode',
            dataIndex: 'greyCode',
          },
          {
            title: '坯布名称',
            key: 'greyName',
            dataIndex: 'greyName',
          },
          {
            title: '布票号',
            key: 'clothVoteCode',
            dataIndex: 'clothVoteCode',
          },
          {
            title: '色号',
            key: 'colorCode',
            dataIndex: 'colorCode',
          },
          {
            title: '色称',
            key: 'colorName',
            dataIndex: 'colorName',
          },
          {
            title: '匹数',
            key: 'houseNum',
            dataIndex: 'houseNum',
          },
        ]
        tb(tbList)
      }

      const operate = (verifyclothResult: number) => {
        if (gridOption.value.getSelectedRows().length !== 1) {
          Message.error({
            content: '请选择一条记录进行操作！',
            duration: 5000,
          })
          return
        }
        var obj = {
          id: gridOption.value.getSelectedRows()[0].id,
          verifyclothResult: verifyclothResult,
        }
        Modal.confirm({
          title: '系统提示',
          content: '确认操作选中的数据?',
          onOk() {
            post({
              url: 'dwQms/Verifycloth/update',
              data: obj,
            }).then(({ code, data }: any) => {
              if (code === 200) {
                Message.success({
                  content: '操作成功',
                  duration: 5000,
                })
                selectHandler()
              } else {
                Message.error({
                  content: '操作失败',
                  duration: 5000,
                })
              }
            })
          },
        })
      }

      const onSelectionChanged = (e: any) => {
        if (gridOption.value.getSelectedRows().length == 1) {
          pageData.totalBranchNum = gridOption.value.getSelectedRows()[0].totalBranchNum
        } else {
          pageData.totalBranchNum = 0
        }
      }

      //流转卡号提取
      const search = (val: any) => {
        post({
          url: 'aps/circulatCard/scanCodeByVerify',
          data: { flowCardCode: dataForm.flowCardCode },
        }).then((res: any) => {
          if (res.code === 200) {
            dataForm.customName = res.data.customName
            dataForm.customOrderCode = res.data.customOrderCode
            dataForm.productName = res.data.productName
            dataForm.colorCode = res.data.colorCode
            dataForm.colorName = res.data.colorName
            dataForm.clothCode = res.data.clothCode
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        })
      }

      const changeScore = () => {
        console.log(pageData.fromData)

        var number = 0
        for (var i = 0; i < pageData.fromData.length; i++) {
          number = number + pageData.fromData[i].defectNum * pageData.fromData[i].defectScore
        }
        dataForm.totalBranchNum = number
        if (number >= 24) {
          dataForm.verifyclothResult = '1'
        } else {
          dataForm.verifyclothResult = '0'
        }
        console.log(dataForm.totalBranchNum)
      }
      return {
        deleteHandler,
        sideOk,
        formRef,
        dataForm,
        addHandler,
        pagination,
        table,
        pageData,
        editHandler,
        selectHandler,
        headerShow,
        nextDoRefreshPage,
        nextDoRefreshSize,
        defaultColDef,
        localeText1,
        gridReady,
        gridReady2,
        gridOption,
        gridOption2,
        drawerTableColumn,
        drawerTableRef,
        tableHeader,
        operate,
        onSelectionChanged,
        search,
        changeScore,
        drawerTableData,
        configaggrid,
        totalObj,
        saveLoading,
        setAudit,
      }
    },
    components: { Toolbar,  },
  }
</script>
<style scoped lang="less">
  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }
</style>
